package file

import (
	partner "gitee.com/binny_w/gin-partner"
	"gitee.com/binny_w/gin_starter/core"
	"github.com/gin-gonic/gin"
	"net/url"
)

func del(c *gin.Context) {
	ss := c.PostFormArray("src[]")
	for _, v := range ss {
		u, err := url.ParseRequestURI(v)
		if err != nil {
			continue
		}
		m := u.Query()
		bucket := ""
		key := ""
		if buckets, ok := m["bucket"]; ok && len(buckets) > 0 {
			bucket = buckets[0]
		}
		if keys, ok := m["key"]; ok && len(keys) > 0 {
			key = keys[0]
		}
		if bucket == "" || key == "" {
			continue
		}
		_ = core.Storage.DeleteObjects(c, bucket, key)
	}
	partner.WriteJsonSuccess(c, nil)
}
